<template>
    <div class="product_details">
        <div class="top">
            <Button type="primary" @click="back()">返回</Button>
        </div>
        <div class="main">
            <Form ref="form" :label-width="200">
                <Form-item :label="this.$t('admin.cid')">
                    <Input v-model="product.cid"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.create_time')">
                    <Input v-model="product.create_time"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.d3id')">
                    <Input v-model="product.d3id"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.description')">
                    <Input v-model="product.description"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.name')">
                    <Input v-model="product.name"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.pid')">
                    <Input v-model="product.pid"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.price')">
                    <Input v-model="product.price"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.rich_text')">
                    <!--<Input v-model="product.rich_text" id="editor"></Input>-->
                    <template>
                        <div id="editor"></div>
                    </template>

                    <!--<div>-->
                <!--　　　　&lt;!&ndash;editor的div为富文本的承载容器&ndash;&gt;-->
                <!--　　　　	<div id="editor">{{product.rich_text}}</div>-->
                <!--　　</div>-->
                </Form-item>
                <Form-item :label="this.$t('admin.thumbnail')">
                    <img :src="'https://s3.cifuwu.com/image/show/origin/'+ product.thumbnail "  alt="未上传图片"/>
                </Form-item>
                <Form-item :label="this.$t('admin.update_time')">
                    <Input v-model="product.update_time"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.url')">
                    <Input v-model="product.url"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.visible')">
                    <Input v-model="product.visible"></Input>
                </Form-item>
                <Form-item :label="this.$t('admin.album')">
                    <Input v-model="product.album"></Input>
                </Form-item>
                <FormItem>
                    <Button type="primary" @click="adminAdd" style="width: 10%;height: 30px">提交</Button>
                </FormItem>
            </Form>

        </div>
    </div>
</template>

<script>
    import {details} from '../../http/API/index'
    import { adminAdd } from '../../http/API/index'
    import { loadimage } from '../../http/API/index'
    export default {
        name: "product_details",
        data(){
            return{
                product : '',
                form : {
                    name : ''
                },
                album : '',
                url : ''
            }
        },

        methods:{
            test(){
                console.log(this.url);
            },
            //获取详情页
            details(){
                details(this.$route.params.pid).then((res) => {
                    if(res.code = 20000){
                        this.product = res.data;
                        console.log(res.data);
                    }else{
                        console.log("提交错误");
                    }
                })
            },
            back(){
                this.$router.go(-1)
              //  window.location.href = document.referrer;//返回上一页并刷新
            },
            // loadimage() {
            //     console.log(this.product.name)
            // }
            //提交
            adminAdd() {
                adminAdd(this.product.name,this.product.description, this.product.tags,this.product.thumbnail,this.product.price, this.product.visible, this.product.d3id, this.product.url,this.product.cid,this.editor.getContent(),this.product.album).then((res) => {
                    if (res.code === 20000) {
                        console.log(res);
                        alert("提交成功");
                    } else {
                        console.log("error");
                    }
                })
            },
        },
        mounted(){

            this.details();
            this.test();
            this.editor = UE.getEditor('editor');
            console.log(this.product.rich_text);
            // this.editor.getContent() = this.product.rich_text;
        },

    }
</script>

<style scoped>
    .ivu-input-type{
        width: 80%;
    }
    .ivu-form{
        width: 90%;
        margin: 30px auto;
        padding-right: 15px;
    }
    img{
        width: 200px;
        height: 200px;
    }
</style>